import type { FormRules } from "element-plus"

/** 表单项类型 */
type FormItemType = "text" | "password" | "select" | "switch" | "checkbox-group" | "radio-group" | "textarea" | "custom"

/** 选择框/复选框/单选框 选项类型 */
interface FormItemOption {
  label: string
  value: string | number | boolean
}

interface BaseFormItem {
  label: string // 标签名
  prop: string // 键名
  type: FormItemType // 表单项的类型
  placeholder?: string // 占位文字
}

interface TextFormItem extends BaseFormItem {
  type: "text" | "textarea" | "password"
}

interface SelectFormItem extends BaseFormItem {
  type: "select"
  options: FormItemOption[]
}

interface SwitchFormItem extends BaseFormItem {
  type: "switch"
}

interface CheckboxGroupFormItem extends BaseFormItem {
  type: "checkbox-group"
  options: FormItemOption[]
}

interface RadioGroupFormItem extends BaseFormItem {
  type: "radio-group"
  options: FormItemOption[]
}

interface CustomFormItem extends BaseFormItem {
  type: "custom"
  slotName?: string // 用于指定插槽名称
}

export type FormItem =
  | TextFormItem
  | SelectFormItem
  | SwitchFormItem
  | CheckboxGroupFormItem
  | RadioGroupFormItem
  | CustomFormItem

/** 通用表单弹窗配置类型 */
export interface ModalFormConfig {
  formItems: FormItem[]
  formRules?: FormRules
}
